//
//  StatusCellBottomView.swift
//  基于Swift的微博设计与实现
//
//  Created by 张源海 on 15/11/27.
//  Copyright © 2015年 张源海. All rights reserved.
//
//
import UIKit

/// 微博 Cell 底部视图
class StatusCellBottomView: UIView {
    
    // MARK: - 构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: 懒加载控件
    
    /// 转发按钮
    private lazy var retweetedButton: UIButton = UIButton(title: " 转发", fontSize: 12, color: UIColor.darkGrayColor(), imageName: "timeline_icon_retweet")
    /// 转发按钮
//    private lazy var retweetedButton: UIButton = UIButton(title: " 转发",
//        fontSize: 12,
//        color: UIColor.lightGrayColor(),
//        imageName: "timeline_icon_retweet")
    /// 评论按钮
    private lazy var commentButton: UIButton = UIButton(title: " 评论",
        fontSize: 12,
        color: UIColor.lightGrayColor(),
        imageName: "timeline_icon_comment")
    /// dian赞按钮
    private lazy var likeButton: UIButton = UIButton(title: " 赞",
        fontSize: 12,
        color: UIColor.lightGrayColor(),
        imageName: "timeline_icon_unlike")
}

// MARK: - 设置界面
extension StatusCellBottomView {
    
    private func setupUI() {
        // 0. 背景颜色
        backgroundColor = UIColor(white: 0.95, alpha: 1.0)
        
        // 1. 添加控件
        addSubview(retweetedButton)
        addSubview(commentButton)
        addSubview(likeButton)
        
        // 2. 自动布局
        retweetedButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.bottom.equalTo(self.snp_bottom)
        }
        commentButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedButton.snp_right)
            make.top.equalTo(retweetedButton.snp_top)
            make.width.equalTo(retweetedButton.snp_width)
            make.height.equalTo(retweetedButton.snp_height)
        }
        likeButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentButton.snp_right)
            make.top.equalTo(retweetedButton.snp_top)
            make.width.equalTo(retweetedButton.snp_width)
            make.height.equalTo(retweetedButton.snp_height)
            
            make.right.equalTo(self.snp_right)
        }
        
        // 3. 分隔线
        let leftView = sepView()
        addSubview(leftView)
        let rightView = sepView()
        addSubview(rightView)
        
        
        
        
//       leftView.snp_makeConstraints { (make) -> Void in
//            make.centerY.equalTo(retweetedButton.snp_centerY)
//            make.left.equalTo(retweetedButton.snp_right)
//            make.width.equalTo(0.5)
//            make.height.equalTo(retweetedButton.snp_height).multipliedBy(0.6)
//        }
//        rightView.snp_makeConstraints { (make) -> Void in
//            make.centerY.equalTo(retweetedButton.snp_centerY)
//            make.left.equalTo(commentButton.snp_right)
//            make.width.equalTo(leftView.snp_width)
//            make.height.equalTo(leftView.snp_height)
//        }
        // 布局
        let w = 0.5
        let scale = 0.4
        
        leftView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedButton.snp_right)
            make.centerY.equalTo(retweetedButton.snp_centerY)
            make.width.equalTo(w)
            make.height.equalTo(retweetedButton.snp_height).multipliedBy(scale)
        }
        rightView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentButton.snp_right)
            make.centerY.equalTo(retweetedButton.snp_centerY)
            make.width.equalTo(w)
            make.height.equalTo(retweetedButton.snp_height).multipliedBy(scale)
        }

    }
    
    /// 分隔线视图
    private func sepView() -> UIView {
        let v = UIView()
        v.backgroundColor = UIColor.darkGrayColor()
        
        return v
    }
}
